package net._708s.logmanager.api;

import java.util.List;

import net._708s.logmanager.domain.Log;
import net._708s.logmanager.service.IndexService;
import net._708s.logmanager.service.SearchService;
import net._708s.logmanager.util.MyParam;

/**
 * 
 * log crd api
 * @author ajian
 *
 */
public class LogCRDApi {
	private IndexService indexService;
	private SearchService searchService;
	private String indexPath;
	
	public String create(Log log){
		return indexService.index(log, indexPath);
	}
	
	public String create(List<Log> logList){
		return indexService.index(logList, indexPath);
	}
	
	public String read(String keyword,int page,int pageSize,String[] types,String[] sources,long range){
		return searchService.searchOfJson(keyword, page, pageSize, indexPath, types, sources, range);
		
	}
	
	public String delete(Log log){
		return indexService.delete(log,indexPath);
	}

	public String delete(List<Log> log){
		return indexService.delete(log,indexPath);
	}
	
	private static LogCRDApi instance=null;

	public static LogCRDApi getInstance(){
		if(instance == null){
			synchronized(LogCRDApi.class){
				if(instance == null){
					String indexPath = MyParam.getDefaultIndexUrl();
					instance = new LogCRDApi(indexPath);
				}
			}
		}
		return instance;
	}

	private LogCRDApi() {

	}
	
	private LogCRDApi(String indexPath){
		this.indexPath = indexPath;
		this.indexService = new IndexService();
		this.searchService = new SearchService();
	}

	public IndexService getIndexService() {
		return indexService;
	}

	public void setIndexService(IndexService indexService) {
		this.indexService = indexService;
	}

	public SearchService getSearchService() {
		return searchService;
	}

	public void setSearchService(SearchService searchService) {
		this.searchService = searchService;
	}

	public String getIndexPath() {
		return indexPath;
	}

	public void setIndexPath(String indexPath) {
		this.indexPath = indexPath;
	}
	
	public String toString(){
		return "["+super.toString()+":indexPath="+indexPath+",indexService="+indexService.toString()+",searchService="+searchService.toString()+"]";	
	}
	
}
